/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package socof_trab1;

/**
 *
 * @author Carlos Pinheiro
 */
public class Laucher extends Thread
{
    private static Laucher lb = new Laucher();
    private DownloadersLaucher downloadersLauncher;
    private ParsersLauncher parsersLauncher;
    
    private Laucher()
    {
        this.downloadersLauncher = DownloadersLaucher.getInstance();
        this.parsersLauncher = ParsersLauncher.getInstance();
    }
    
    public static Laucher getInstance()
    {
        return Laucher.lb;
    }
    
    public void setMaxBandwithAllocation (long maxBandwithAllocation)
    {
        this.downloadersLauncher.setMaxBandwidthAllocation(maxBandwithAllocation);
    }
    
    public void setMaxCpuUsage (double maxCpuUsage)
    {
        this.parsersLauncher.setMaxCpuUsage(maxCpuUsage);
    }
    
    public void setDownloadersLimit(int downloadersLimit)
    {
        this.downloadersLauncher.setDownloadersLimit(downloadersLimit);
    }

    public void setParsersLimit(int parsersLimit)
    {
        this.parsersLauncher.setParsersLimit(parsersLimit);
    }

    
    @Override
    public void run()
    {
        try
        {
            this.downloadersLauncher.start();
            this.parsersLauncher.start();
            
            this.downloadersLauncher.join();
            this.parsersLauncher.join();
            
        }
        catch (InterruptedException ex)
        {
            this.downloadersLauncher.interrupt();
            this.parsersLauncher.interrupt();
        }
    }    
}
